//
// Created by SD on 2023/12/11.
//
#include<bits/stdc++.h>
using namespace std;
struct  node{
    int begin;
    int end;
}exam[1000005];
bool cmp(node a, node b)
{
    return  a.end< b.end;
}
int main()
{
    int n  = 0,ans = 0;
    cin >> n;
    for(int i = 1;i <= n;i++)
    {
        cin >> exam[i].begin  >> exam[i].end ;
    }
    sort(exam + 1, exam + 1 + n ,cmp);
    int pos = 0;
    for(int i = 1;i <= n;i++)
    {
        if(pos <= exam[i].begin)
        {
            pos = exam[i].end;
            ans++;
        }
    }
    cout << ans;
    return 0;
}